package com.hmo.appshop;

import android.graphics.Color;
import android.graphics.drawable.ColorDrawable;
import android.os.Bundle;
import android.view.LayoutInflater;
import android.view.View;
import android.view.ViewGroup;
import android.widget.Button;

import androidx.annotation.NonNull;
import androidx.annotation.Nullable;
import androidx.fragment.app.DialogFragment;

import com.hmo.appshop.databinding.LoadingBinding;

import java.util.Objects;

public class UpDataDialog extends DialogFragment {
    private LoadingBinding inflate;
    private String message;
    private MainActivity.DialogBack dialogBack;

    public UpDataDialog(String message, MainActivity.DialogBack dialogBack) {
        this.message = message;
        this.dialogBack=dialogBack;
    }

    @Nullable
    @Override
    public View onCreateView(@NonNull LayoutInflater inflater, @Nullable ViewGroup container, @Nullable Bundle savedInstanceState) {
        Objects.requireNonNull(Objects.requireNonNull(getDialog()).getWindow()).setBackgroundDrawable(new ColorDrawable(Color.TRANSPARENT)); //去除默认白色边框
        inflate = LoadingBinding.inflate(inflater, container, false);
        return inflate.getRoot();
    }

    @Override
    public void onActivityCreated(@Nullable Bundle savedInstanceState) {
        super.onActivityCreated(savedInstanceState);
        inflate.loadingTv2.setText(message);
        inflate.loadingTv1.setText("发现新版本:");
        Button loadingBtn1 = inflate.loadingBtn1;
        loadingBtn1.setText("取消");
        loadingBtn1.setOnClickListener(new View.OnClickListener() {
            @Override
            public void onClick(View view) {
                dismiss();
            }
        });

        inflate.loadingBtn2.setOnClickListener(new View.OnClickListener() {
            @Override
            public void onClick(View view) {
                dialogBack.callInit();
                dismiss();
            }
        });
        inflate.loadingBtn2.setText("立即更新");

        loadingBtn1.requestFocus();
    }

    @Override
    public void onDestroyView() {
        super.onDestroyView();
        inflate=null;
    }
}
